package com.ruoyi.web.controller.system

import com.ruoyi.common.core.controller.BaseController
import com.ruoyi.common.core.domain.AjaxResult
import com.ruoyi.common.core.domain.model.RegisterBody
import com.ruoyi.common.utils.MyStringUtils
import com.ruoyi.framework.web.service.SysRegisterService
import com.ruoyi.system.service.ISysConfigService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

/**
 * 注册验证
 *
 * @author ruoyi
 */
@RestController
open  class SysRegisterController : BaseController() {

    @Autowired
    private lateinit var registerService: SysRegisterService
    @Autowired
    private lateinit var configService: ISysConfigService

    @PostMapping("/register")
    open  fun register(@RequestBody user: RegisterBody?): AjaxResult {
        if ("true" != configService.selectConfigByKey("sys.account.registerUser")) {
            return error("当前系统没有开启注册功能！")
        }
        val msg: String = registerService.register(user)
        return if (MyStringUtils.isEmpty(msg)) success() else error(msg)
    }
}
